//index.js
//获取应用实例
var app = getApp()
var util = require('../../untils/untils.js')  

Page({
  data: {
    banner: null,
    autoplay: true,
    interval: 2000,
    duration: 1000,
    txtAds: null,
    userInfo: {},
    msgList: null,
    tabshow1: false,
    tabshow2: true,
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    advertise: null
  },
  /*
  * 首页banner
  */
  setBanner: function () {
    let that = this;
    //util.fetch(app.globalData.gwapi + '/v1/h/images', function (data) {
    util.fetch(app.globalData.globalReqUrl + '/user/banner', function (data) {
      that.setData({
        banner: data.content
      });
    });
  },
  /**
   * 首页文字广告
   */
  setTxtAds: function () {
    let that = this;
    //util.fetch(app.globalData.gwapi + '/v1/wx/adText', function (data) {
    util.fetch(app.globalData.globalReqUrl + '/user/notice', function (data) {
      that.setData({
        //txtAds: data.data.text
        //txtAds: '联系微信：w2013sheng'
        msgList: data.content
      });
    });
  },
  //随机出题
  setMusicShow: function () {
    var that = this;
    __wxConfig.debug && console.log("setMusciShow")
    wx.request({
      url: app.globalData.globalReqUrl + '/music/setMusicShow',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      method: 'POST',
      success: function (res) {
        if (res.data.content != -1) {
          __wxConfig.debug && console.log("setMusciShow：", res.data.content)
          that.setData({
            tabshow1: res.data.content.show1,
            tabshow2: res.data.content.show2,
          });
        } else {
          console.log("请求失败")
        }
      },
      fail: function () {
        console.log("请求失败")
      }
    })
  },
  toidcard: function () {
    wx.navigateTo({
      url: '../idcard/idcard'
    })
  },
  toexp:function(){
    wx.navigateTo({
      url: '../exp/index/index'
    })
  },
  tohuilv:function(){
    wx.navigateTo({
      url: '../exchangeCal/exchangeCal'
    })
  },
  /**
   * 模块入口
   */
  setModule: function(){

  },
  /**
   * 入口
   */
  onLoad: function () {
    var that = this;
    that.setBanner();
    that.setTxtAds();
    // that.setSubBanner();
    that.setModule();
    wx.showShareMenu({
      withShareTicket: true
    })  
    that.setMusicShow();
  },
  onShow: function () {
    var that = this;
    that.setMusicShow();
  },

  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '搜【小棉袄】',
      path: '/pages/nindex/index',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },

  jumphomepage: function (e) {
    app.globalData.userInfo = e.detail.userInfo
    wx.navigateTo({
      url: '../homepage/homepage'
    })
  },

  jumpweather: function (e) {
    app.globalData.userInfo = e.detail.userInfo
    wx.navigateTo({
      url: '../weather/index/index'
    })
  },
  jumpinfo: function () {
    wx.navigateTo({
      url: '/pages/info/info',
    })
  },
  jump5: function () {
    wx.navigateTo({
      url: '/pages/us/us',
    })
  },
  jumpZan: function () {
    console.log("jingrugeizan")
    wx.navigateToMiniProgram({
      appId: 'wx18a2ac992306a5a4',
      path: 'pages/apps/largess/detail?id=092zDpdM9wQ=',
      extraData: {
        foo: 'bar'
      },
      envVersion: 'develop',
      success(res) {
        // 打开成功
      }
    })
  },
  
   
});
